<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE html>
<html>
<head>
    <title></title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入bootstrap -->
    <link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
    <!-- 引入JQuery  bootstrap.js-->
    <script src="/js/jquery-3.2.1.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
</head>
<body>
<!-- 顶栏 -->
<jsp:include page="top.jsp"></jsp:include>
<!-- 中间主体 -->
<div class="container" id="content">
    <div class="row">
        <jsp:include page="menu.jsp"></jsp:include>
        <div class="col-md-10">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="row">
                        <h1 style="text-align: center;">添加学生信息</h1>
                    </div>
                </div>
                <div class="panel-body">
                    <form class="form-horizontal" role="form" action="/admin/addStudent" id="editfrom" method="post">
                        <div class="form-group">
                            <label for="userid" class="col-sm-2 control-label">学号</label>
                            <div class="col-sm-10">
                                <input type="number" class="form-control" id="userid" name="userid" placeholder="请输入学号">
                            </div>
                            <%--学号存在时给出的提示信息--%>
                            <span id="span_userid" style="float: right"></span>

                        </div>


                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-2 control-label">姓名</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="inputPassword3" name="username"
                                       placeholder="请输入姓名">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-2 control-label">性别</label>
                            <div class="col-sm-10">
                                <label class="checkbox-inline">
                                    <input type="radio" name="sex" value="男" checked>男
                                </label>
                                <label class="checkbox-inline">
                                    <input type="radio" name="sex" value="女">女
                                </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-2 control-label">出生年份</label>
                            <div class="col-sm-10">
                                <input type="date" value="1996-09-02" name="birthyear"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-2 control-label" name="grade">入学时间</label>
                            <div class="col-sm-10">
                                <input type="date" value="2015-09-02" name="grade"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-2 control-label" name="grade">所属院系</label>
                            <div class="col-sm-10">
                                <select class="form-control" name="collegeid">
                                    <c:forEach items="${collegeList}" var="item">
                                        <option value="${item.collegeid}">${item.collegename}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="form-group" style="text-align: center">
                            <button class="btn btn-default" type="submit">提交</button>
                            <button class="btn btn-default" type="reset">重置</button>
                        </div>
                    </form>
                </div>

            </div>

        </div>
    </div>
</div>
<div class="container" id="footer">
    <div class="row">
        <div class="col-md-12"></div>
    </div>
</div>
</body>
<script type="text/javascript">
    $("#nav li:nth-child(2)").addClass("active")

    //查看学号是否存在
    function checkUserid() {
        var userid = $("#userid").val();
        // alert(userid)

        var allData = {
            userid: userid
        };

        $.ajax({
            url: "${pageContext.request.contextPath}/admin/checkStudentId",
            contentType: "application/json;charset=UTF-8",
            data: JSON.stringify(allData),//'{"username":username}',
            dataType: "json",
            type: "post",
            success: function (data) {
                if (data.flag) {
                    //学号不存在，可以添加
                    $("#userid").css("border", "");
                    $("#span_userid").text("");
                } else {
                    //学号已经存在
                    $("#userid").css("border", "1px solid red");
                    $("#span_userid").text(data.errorMsg);
                    $("#span_userid").css("color", "red");
                }
            }
        });
    }

    $(function () {

        $("#userid").blur(checkUserid);

    });


</script>
</html>
